package com.futao.springbootlearn20220224.validdemo;

import lombok.Getter;
import lombok.Setter;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

/**
 * @author futao@gmail.com
 * @date 2022/3/28
 */
@Getter
@Setter
public class ValidObject {
    @Size(max = 10, message = "用户名最长10位")
    private String username;
    @NotNull(message = "年龄不能为空")
    private Integer age;
    /**
     * 如果字段是个对象，这个对象内部的字段也需要校验，则需要标记@Valid注解
     */
    @Valid
    @NotNull(message = "手机号不可为空")
    private Phone phone;

    @Getter
    @Setter
    public static class Phone {
        @Size(min = 11, max = 11, message = "手机号固定11位")
        private String phone;
    }
}
